﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using ERP_RORZE_SYSTEM;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ERP_RORZE_DLL.Business
{
    public partial class panel_IQLastTimeRemain : UserControl
    {
        
        public panel_IQLastTimeRemain()
        {
            InitializeComponent();
            LoadData();
        }

        //////////////////////////////////////////////
        /// Load Data to Grid View
        //////////////////////////////////////////////
        private void LoadData()
        {
            DataSet sourceDataSet = new DataSet();
            INISettings mySettings = new INISettings();
            SQLManagement mySQLManagement = new SQLManagement();
            mySQLManagement.SQLConnectionString = mySettings.SQLConnectionString;
            string sql = "SELECT LastDate, IQNo, SUM(Remain) AS Remain FROM [241_IQLastTimeRemain] GROUP BY IQNo, LastDate ORDER BY IQNo";
            sourceDataSet = mySQLManagement.SQL_Query(sql);
            if (sourceDataSet != null)
            {
                gridIQLastTimeRemain.DataSource = sourceDataSet.Tables[0];
            }
            else
            {
                DataTable newTable = new DataTable();
                newTable.Columns.Add("LastDate", typeof(DateTime));
                newTable.Columns.Add("IQNo", typeof(string));
                newTable.Columns.Add("Remain", typeof(float));                
                gridIQLastTimeRemain.DataSource = newTable;
            }
            IQLastTimeRemain.Columns[0].Caption = "Last Date";
            IQLastTimeRemain.Columns[1].Caption = "IQ No";
            IQLastTimeRemain.Columns[2].Caption = "Remain";
            IQLastTimeRemain.Columns[2].DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
            IQLastTimeRemain.Columns[2].DisplayFormat.FormatString = "n0";            
            IQLastTimeRemain.BestFitColumns();
        }
    }
}
